package com.rw.tool.util.expression.element;

import com.rw.tool.util.expression.exception.SignException;

import java.util.Arrays;
import java.util.List;

/**
 * 表达式中的括号
 */
public abstract class Parentheses extends Sign {
    private final List<String> sign;

    protected Parentheses(String... sign) {
        this.sign = Arrays.asList(sign);
    }

    @Override
    public List<String> getSign() {
        return sign;
    }

    /**
     * 根据字符串解析出对应的括号
     */
    public static Parentheses of(String sign) {
        if (RightParentheses.RIGHT.getSign().contains(sign)) {
            return RightParentheses.RIGHT;
        } else if (LeftParentheses.LEFT.getSign().contains(sign)) {
            return LeftParentheses.LEFT;
        }
        throw new SignException(sign);
    }

    /**
     * 获取符号列表
     */
    public static List<Parentheses> getParenthesesValues() {
        return Arrays.asList(LeftParentheses.LEFT, RightParentheses.RIGHT);
    }
}
